

public class Simulation implements Runnable {

	private boolean runs1,runs2;
	
	private Thread simThread;
	private AntSimulation antSim;
	
	public Simulation(AntSimulation as){
		super();
		antSim=as;
		simThread=null;
		runs1=true;
		runs2=true;
	}//constructor
	
	
	public  void run() {
		System.out.println("Thread gestarted");
			
					/*AntSimulation.initialzeSimulation();*/
		while(runs1){	
			
			while(runs2){
						try {
						//	System.out.println("Ameise berechnen beginnt bei :j "+antSim.getStat_J());
							antSim.simulate(antSim.getStat_J());
						} catch (InterruptedException e) {
						// TODO Auto-generated catch block
							System.out.println("simulation unterbrochen");
							break;
						}
			}
			try {
				simThread.sleep(10);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		System.out.println("Simualtion Thread ended.");
		
	}//run()
	

	public synchronized  void start(){
		if(simThread==null){
			simThread=new Thread(this);
			simThread.start();
		}
	}
	
	public synchronized void start_new_simulation(){
		//this.interrupt_simulation();
		System.out.println("\n*******\nwill neue Simulation starten run-variabeln: "+runs1+" "+runs2);
		this.exit_Simulation();
		antSim.initialzeSimulation();
	//	antSim.setStat_j(0);
			this.runs1=true;
			this.runs2=true;
			this.start();
	}
	
	public synchronized void interrupt_simulation(){
		runs2=false;
			simThread.interrupt();	
	}
	
	public  synchronized void continue_simulation(){
		System.out.println("\n****\nSimulation wird weitergefuehrt");
		runs2=true;
		//simThread.start();
		
		//continues
		/*this.exit_Simulation();
		AntSimulation.stat_i=0;
		AntSimulation.stat_j=0;
		this.runs1=true;
		runs2=true;
		this.start();*/
		
	}
	
	public synchronized void exit_Simulation(){
		this.runs1=false;
		this.runs2=false;
		if(simThread!=null)
				simThread=null;
		System.out.println("Simulation exit gemacht + thread referenz "+ simThread);
	}
}//class
